<article class="module width_full">
	<header>
		<h3 class="tabs_involved">商品列表111</h3>
		<ul class="tabs">
			<li><input type="button" class="alt_btn" onclick="searchGoods({'submit':filterResult,'mode':'normal','data':'<?php echo isset($searchParam)?$searchParam:"";?>','seller_id':<?php echo isset($seller_id)?$seller_id:"";?>});" value="检索" /></li>
			<li><input type="button" class="alt_btn" onclick="window.location.href='<?php echo IUrl::creatUrl("/seller/goods_edit");?>';" value="添加商品" /></li>
			<li><input type="button" class="alt_btn" onclick="selectAll('id[]');" value="全选" /></li>
			<li><input type="button" class="alt_btn" onclick="delModel({'form':'goodsForm','link':'<?php echo IUrl::creatUrl("/seller/goods_del");?>','name':'id[]'})" value="删除" /></li>
			<li><input type="button" class="alt_btn" onclick="delModel({'form':'goodsForm','link':'<?php echo IUrl::creatUrl("/seller/goods_status/is_del/2");?>','name':'id[]','msg':'选择的商品下架？'})" value="下架" /></li>
			<li><input type="button" class="alt_btn" onclick="delModel({'form':'goodsForm','link':'<?php echo IUrl::creatUrl("/seller/goods_status/is_del/3");?>','name':'id[]','msg':'选择的商品申请上架？'})" value="申请上架" /></li>
            <li><input type="button" class="alt_btn" onclick="goodsSetting();" value="批量编辑" /></li>
			<li><input type="button" class="alt_btn" onclick="window.open('<?php echo IUrl::creatUrl("/seller/goods_report/?".$searchParam."");?>');" value="导出Excel" /></li>
		</ul>
	</header>

	<form action="<?php echo IUrl::creatUrl("/seller/goods_del");?>" method="post" name="goodsForm">
		<table class="tablesorter" cellspacing="0">
			<colgroup>
				<col width="25px" />
				<col />
				<col width="150px" />
				<col width="70px" />
				<col width="70px" />
				<col width="70px" />
				<col width="70px" />
				<col width="80px" />
			</colgroup>

			<thead>
				<tr>
					<th class="header"></th>
					<th class="header">商品名字</th>
					<th class="header">分类</th>
					<th class="header">销售价</th>
					<th class="header">库存</th>
					<th class="header">状态</th>
					<th class="header">排序</th>
					<th class="header">操作</th>
				</tr>
			</thead>

			<tbody>
				<?php foreach($items=$this->goodHandle->find() as $key => $item){?>
				<tr>
					<td><input name="id[]" type="checkbox" value="<?php echo isset($item['id'])?$item['id']:"";?>" /></td>
					<td><img src='<?php echo IUrl::creatUrl("/pic/thumb/img/".$item['img']."/w/100/h/100");?>' class="ico" /><a href="javascript:jumpUrl('<?php echo isset($item['is_del'])?$item['is_del']:"";?>','<?php echo IUrl::creatUrl("/site/products/id/".$item['id']."");?>')" title="<?php echo htmlspecialchars($item['name']);?>"><?php echo isset($item['name'])?$item['name']:"";?></a></td>
					<td>
                        <?php foreach($items=Api::run('getCategoryExtendNameByCategoryid',array('id'=>$item['id'])) as $key => $catName){?>
                        [<?php echo isset($catName['name'])?$catName['name']:"";?>]
                        <?php }?>
					</td>
					<td><?php echo isset($item['sell_price'])?$item['sell_price']:"";?></td>
					<td><?php echo isset($item['store_nums'])?$item['store_nums']:"";?></td>
					<td class="<?php echo $item['is_del']==0 ? "green":"red";?>"><?php echo goods_class::statusText($item['is_del']);?></td>
					<td><input class="tiny" type="text" value="<?php echo isset($item['sort'])?$item['sort']:"";?>" onchange="changeSort(<?php echo isset($item['id'])?$item['id']:"";?>,this);" /></td>
					<td>
						<a href="<?php echo IUrl::creatUrl("/seller/goods_edit/id/".$item['id']."/type/".$item['type']."");?>"><img src="<?php echo $this->getWebSkinPath()."images/main/icn_edit.png";?>" title="编辑" /></a>
						<a href="javascript:delModel({'link':'<?php echo IUrl::creatUrl("/seller/goods_del/id/".$item['id']."");?>'})"><img src="<?php echo $this->getWebSkinPath()."images/main/icn_del.png";?>" title="删除" /></a>
					</td>
				</tr>
				<?php }?>
			</tbody>
		</table>
	</form>
	<?php echo $this->goodHandle->getPageBar();?>
</article>

<script type="text/javascript">
//检索商品
function filterResult(iframeWin)
{
	var searchForm   = iframeWin.document.body;
	var searchString = $(searchForm).find("form").serialize();
	var jumpUrl      = creatUrl("/seller/goods_list");
	jumpUrl         += jumpUrl.indexOf("?") == -1 ? "?"+searchString : "&"+searchString;
	window.location.href = jumpUrl;
}

//修改排序
function changeSort(gid,obj)
{
	var selectedValue = obj.value;
	$.getJSON("<?php echo IUrl::creatUrl("/seller/ajax_sort");?>",{"id":gid,"sort":selectedValue});
}

//商品详情的跳转连接
function jumpUrl(is_del,url)
{
	is_del == 0 ? window.open(url) : alert("该商品没有上架无法查看");
}

//upload csv file callback
function artDialogCallback(message)
{
	message ? alert(message) : window.location.reload();
}

// 商品批量设置
function goodsSetting()
{
	if($('input:checkbox[name="id[]"]:checked').length > 0)
	{
		var idArray = [];
		var idString = '';
		$('input:checkbox[name="id[]"]:checked').each(function(i)
		{
			idArray.push(this.value);
		});
		idString = idArray.join(',');

		var urlVal = "<?php echo IUrl::creatUrl("/goods/goods_setting/id/@id@/seller_id/@seller_id@");?>";
		urlVal = urlVal.replace("@id@",idString).replace("@seller_id@","<?php echo isset($this->seller['seller_id'])?$this->seller['seller_id']:"";?>");
		art.dialog.open(urlVal,{
			id:'goods_setting',
			title:'商品批量设置',
			okVal:'保存设置',
			ok:function(iframeWin, topWin){
				var formObject = iframeWin.document.forms[0];
				if(formObject.onsubmit() == false)
				{
					return false;
				}
				loadding();
				formObject.submit();
				return false;
			}
		});
	}
	else
	{
		alert("请选择您要操作的商品");
	}
}
</script>
